<template>
  <div class="app-container">
    <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" @export="handleExport">
    </wms-form>
    <wms-table class="table-click" :loading="loading" :data-list="ibDetailsList" :column="column"
      :pageInfo="queryParams" @get-list="getList" @row-click="handleRowClick" />
    <ib-register v-if="showRegister" v-model="showRegister" :registerInfo="registerInfo" />
  </div>
</template>

<script setup name="register_return">
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import IbRegister from '../ibRegister/index.vue'
import { listIbDetails, getIbDetails, delIbDetails, addIbDetails, updateIbDetails } from "@/api/wms/ibDetails";
import { data, column, formList } from './index.js'
import { listStation } from "@/api/wms/station";
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);

const ibDetailsList = ref([]);
const loading = ref(true);

let showRegister = ref(false)
let registerInfo = ref({
  pageType: 'RETURN',
  ibDetailId: null,
  ibMasterType: null,
  zoneId: 201
})
/** 查询[成品收货]入库明细单列表 */
function getList() {
  loading.value = true;
  // 仅查找成品相关单据
  queryParams.ibMasterType = 'WO_IN_WIP';
  listIbDetails(proxy.addDateRange(queryParams, queryParams.dateRange)).then(response => {
    ibDetailsList.value = response.rows;
    queryParams.total = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParams.dateRange = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('wms/ibDetails/export', {
    ...queryParams
  }, `ibDetails_${new Date().getTime()}.xlsx`)
}

const handleRowClick = (row) => {
  showRegister.value = true
  registerInfo.value.ibDetailId = row.ibDetailId
}
getList();
</script>
